var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, o, i) {
    var n, s = arguments.length, h = s < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) h = Reflect.decorate(t, e, o, i); else for (var r = t.length - 1; 0 <= r; r--) (n = t[r]) && (h = (s < 3 ? n(h) : 3 < s ? n(e, o, h) : n(e, o)) || h);
    return 3 < s && h && Object.defineProperty(e, o, h), h;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("AudioManager"), c = e("PersonView"), l = e("GameData"), d = e("EggsManager"), u = e("DataManager"), p = e("LoadManager"), h = e("UIManager"), f = e("WebManager"), g = cc._decorator, m = g.ccclass, y = g.property, v = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.target = null, t.btnNode = null, t.personView = null, t.touchArea = null, 
        t.touchId = null, t.isCheck = !1, t.isCheck2 = !1, t.isTimer = !1, t.idx = 19, t.personIdx = 3, 
        t.time = 0, t.pos = cc.v2(), t.originPos = cc.v2(), t;
    }
    return i(t, e), t.prototype.onEnable = function() {
        -1 == d.default.getInstance().checkEggPerson(this.idx) && this.addTouchEvent();
    }, t.prototype.onDisable = function() {
        this.removeTouchEvent();
    }, t.prototype.onDestroy = function() {
        cc.systemEvent.off("refresh_person_skin", this.doRefresh, this);
    }, t.prototype.onClick = function() {
        var e = this;
        -1 == d.default.getInstance().checkEggPerson(this.idx) && (!GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) || l.GD.isFollow ? this.doReward() : h.default.getInstance().loadPnl("eggsTips").then(function(t) {
            t && (t.target = e.node);
        }));
    }, t.prototype.doReward = function() {
        var t = this;
        f.default.getInstance().sentLog("获得皮肤彩蛋id:" + this.idx), s.default.getInstance().playAudio("彩蛋皮肤戴拿凹凸曼"), 
        this.node.on("egg_get", this.doGet, this), h.default.getInstance().loadPopPnl("egg_get", {
            type: r.RewardType.SKIN,
            idx: this.idx,
            target: this.node
        }, function() {
            t.target.setPosition(t.pos), t.btnNode.setPosition(t.originPos);
        });
    }, t.prototype.doGet = function() {
        this.removeTouchEvent(), d.default.getInstance().updateEggPerson(this.idx), l.GD.personIdx = -1 - this.idx, 
        l.GD.eggsHintState = 1, u.default.getInstance().save(), cc.systemEvent.off("refresh_person_skin", this.doRefresh, this), 
        this.node.off("egg_get"), h.default.getInstance().hideAllPnl(), h.default.getInstance().showPnl("start");
    }, t.prototype.start = function() {
        this.pos = this.target.getPosition();
    }, t.prototype.init = function() {
        this.originPos = this.target.getPosition(), this.btnNode = new cc.Node(), p.default.getInstance().loadSpriteFrame({
            url: "image/eggs/戴拿凹凸曼@2x",
            sprite: this.btnNode.addComponent(cc.Sprite)
        }), this.btnNode.zIndex = -1, this.btnNode.setPosition(this.originPos), this.btnNode.parent = this.target.parent, 
        this.node.on("follow_success", this.doReward, this), this.doRefresh(), cc.systemEvent.on("refresh_person_skin", this.doRefresh, this);
    }, t.prototype.doRefresh = function() {
        var t;
        this.target.setPosition(this.originPos), this.btnNode.setPosition(this.originPos), 
        this.personView && this.personView.personIdx == this.personIdx && l.GD.hasSkin(this.personIdx) && -1 == d.default.getInstance().checkEggPerson(this.idx) ? (this.node.active = !0, 
        (t = this.target.getComponent(cc.Button)) && 0 == t.interactable ? (this.touchArea.active = !0, 
        this.btnNode.active = !0) : (this.touchArea.active = !1, this.btnNode.active = !1)) : (this.node.active = !1, 
        this.btnNode.active = !1);
    }, t.prototype.addTouchEvent = function() {
        this.touchArea.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.removeTouchEvent = function() {
        this.touchArea.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.touchStartHandler = function(t) {
        var e;
        null == this.touchId && (this.touchId = t.getID()), this.touchId == t.getID() && (e = t.getLocation(), 
        t = this.target.convertToNodeSpaceAR(e), Math.abs(t.x) <= this.target.width / 2 && Math.abs(t.y) <= this.target.height / 2 ? this.isTimer = !0 : (Math.abs(t.x) > this.target.width / 2 || Math.abs(t.y) > this.target.height / 2) && (e = this.btnNode.convertToNodeSpaceAR(e), 
        Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (this.isCheck2 = !0)));
    }, t.prototype.touchMoveHandler = function(t) {
        this.touchId == t.getID() && (this.isCheck ? this.target.setPosition(this.target.parent.convertToNodeSpaceAR(t.getLocation())) : this.isCheck2 && this.btnNode.setPosition(this.btnNode.parent.convertToNodeSpaceAR(t.getLocation())));
    }, t.prototype.touchEndHandler = function(t) {
        var e, o;
        this.touchId = null, this.isTimer && (this.isTimer = !1), this.isCheck && (this.isCheck = !1), 
        this.isCheck2 && (this.isCheck2 = !1, e = this.btnNode.convertToWorldSpaceAR(cc.Vec2.ZERO), 
        o = this.personView.node.convertToWorldSpaceAR(cc.Vec2.ZERO), 0 <= e.y - o.y && e.y - o.y <= 100 && Math.abs(e.x - o.x) < 100 && (cc.tween(this.btnNode).to(.1, {
            scale: 1.1
        }).to(.1, {
            scale: 1
        }).start(), this.onClick(t)));
    }, t.prototype.update = function(t) {
        this.isTimer ? (this.time < 2 && (this.time += t), 2 <= this.time && (this.isCheck = !0)) : this.time = 0;
    }, a([ y(cc.Node) ], t.prototype, "target", void 0), a([ y(c.default) ], t.prototype, "personView", void 0), 
    a([ y(cc.Node) ], t.prototype, "touchArea", void 0), a([ m ], t);
}(cc.Component);

n.default = v;